#include "PageLibPreprocessor.hpp"


void PageLibPreprocessor::cutRedundantPages()
{
    std::vector<int> index;
    index.reserve(700);

    /*将i和i后面的依次比较，如果有网页跟i相似度较高，则将网页i删除*/
    for(size_t i = 0; i < _pageList.size()-1;++i)
    {
        for(size_t j = i+1; j< _pageList.size();++j)
        {
            if(_pageList[i]  == _pageList[j])
            {
                index.push_back(i);
                break;
            }
        }
    }
    //注意迭代器失效问题----->解决办法，从后面往前删
    for(size_t idx = 0;idx < index.size();++idx)//遍历要删除的文字id的容器
    {
        cout << "删掉的文字标题 ：" << _pageList[idx].getTitle() << "--->"
             << _pageList[idx].getDocId() << endl;

         _pageList.erase(_pageList.begin() + index[idx]);//删除对应网页
         /* auto it = std::remove_if(_pageList.begin(), _pageList.end(),[](int idx); */ 
    }

    /* 重置去重后留下来的网页的id，依次递增 */
    for(size_t idx = 0;idx < _pageList.size();++idx)
    {
        _pageList[idx].reSetDocId(idx);
    }
}
